<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
      .active {
        font-size: 30px;
        color: blue;
      }
      .helloworld {
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 第一种 -->
      <p class="active">hello1</p>

      <!-- 第二种：对象用法 -->
      <!-- <p :class="{类名：boolean}">hello1</p> -->
      <!-- 如果是true，就表示添加这个类名，如果是 false，就代表不添加这个类名 -->
      <p :class="{ active: true }">hello1</p>
      <p :class="{ active: isActive, helloworld: isActive }">hello1</p>
      <button @click="isActive = !isActive">改变active</button>

      <!-- 和普通的类同时存在，不会覆盖，会进行合并 -->
      <p :class="{ active: isActive }" class="helloworld">hello1</p>

      <!-- 可以把类名存在对象里 -->
      <p :class="classObj">hello1</p>

      <!-- 第三种：数组语法(不常用) -->
      <p :class="[ helloworldClass, activeClass ]">helle2</p>

      <!-- 数组和对象结合使用 -->
      <p :class="[ helloworldClass, { active: isActive } ]">hello3</p>
    </div>
  </body>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      el: "#app",
      data() {
        return {
          isActive: true,
          classObj: {
            active: true,
            helloworld: true,
          },
          activeClass: "active",
          helloworldClass: "helloworld",
        };
      },
      methods: {},
    });

    app.mount("#app");
  </script>
</html>
